<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ page import="com.DBCon" %>
    <%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<%@ include file="../bootstrap.jsp"%>
<style>
.EditForm{
padding:40px;
}
</style>
<!-- 
                   可能需要使用的标签
					<small id="PassWordHelp" class="form-text text-muted">
						学院账号的默认密码为”123456“</small>
 -->
<meta charset="UTF-8">
<title>学院信息修改</title>
</head>
<body>
<%
//接受编辑按钮的参数
//接受返回的页码
String pg=request.getParameter("pg");
//接收的学院账号、名称的情况
String DepNumFB=(String)request.getAttribute("DepNumFB");
String DepNameFB=(String)request.getAttribute("DepNameFB");
//接收填写表单前的数据
String DepNum=(String)request.getAttribute("DepNum");
String DepName=(String)request.getAttribute("DepName");
String DepConName=(String)request.getAttribute("DepConName");
String DepConEmail1=(String)request.getAttribute("DepConEmail1");
String DepConEmail2=(String)request.getAttribute("DepConEmail2");
String submitFB=(String)request.getAttribute("submitFB");
session.setAttribute("pagenumber",pg);//放进session，servlet调用
System.out.println("**********************************");
System.out.println(DepNum);
System.out.println(DepName);
System.out.println(DepConName);
System.out.println(DepConEmail1);
System.out.println(DepConEmail2);
System.out.println(submitFB);
System.out.println("**********************************");


//接收从编辑链接穿来的参数
String UserNum=request.getParameter("usernum");
String UserDepName=request.getParameter("userdepname");

if(UserNum==null){
	UserNum=(String) request.getSession().getAttribute("EditUserNum");
}else{
	session.setAttribute("EditUserNum",UserNum);
}
if(UserDepName==null){
	UserDepName=(String) request.getSession().getAttribute("EditDepName");
}else{
	session.setAttribute("EditDepName",UserDepName);
}

System.out.println("**********************************");
System.out.println(UserNum);
System.out.println(UserDepName);
System.out.println("**********************************");
String sql="Select * from department where DepNum='"+UserNum+"'";
try{
	ResultSet rs=new DBCon().find(sql);
	while(rs.next()){
		//将邮箱信息拆分
		String UserDepConEmail=rs.getString("DepConEmail");
		String[] UserDepConEmailarray=UserDepConEmail.split("@");
		//获取邮箱前缀
		String UserDepConEmail1=UserDepConEmailarray[0]; 
		//获取邮箱后缀
		String UserDepConEmail2=UserDepConEmailarray[1];
		System.out.println("UserDepConEmail1="+UserDepConEmail1);
		System.out.println("UserDepConEmail1"+UserDepConEmail2);
	%>
		<div class="EditForm">
		<h4 style="font-weight: bolder; left: 20px">编辑学院信息</h4>
			<form action="AddDepNum">
				<div class="form-row">
					<div class="form-group col-md-6">
						<%
						if (DepNumFB == "不存在账号" || DepNumFB=="修改前后账号相同") {
						%>
						<label for="InputDepNum">学院账号</label>
						<div class="input-group isinvalid">
							<div class="input-group-prepend">
								<span class="input-group-text" id="addon-wrapping">106512</span>
							</div>
							<input type="number" class="form-control" name="DepNum"
								id="InputDepNum" placeholder="两位数字"
								aria-describedby="addon-wrapping"
								oninput="value=value.slice(0,2)"
								value=<%=DepNum.substring(6, DepNum.length())%> required>
						</div>
						<%
						} else if (DepNumFB == "存在账号") {
						%>
						<label for="InputDepNum">学院账号</label>
						<div class="input-group isinvalid">
							<div class="input-group-prepend">
								<span class="input-group-text" id="addon-wrapping">106512</span>
							</div>
							<input type="number" class="form-control is-invalid" name="DepNum"
								id="InputDepNum" placeholder="两位数字"
								aria-describedby="addon-wrapping"
								oninput="value=value.slice(0,2)"
								value=<%=DepNum.substring(6, DepNum.length())%> required>
							<div class="invalid-feedback">该账号已被使用</div>
						</div>
						<%
						} else if (DepNumFB == null) {
						%>
						<!-- 为空正常显示标签 -->
						<label for="InputDepNum">学院账号</label>
						<div class="input-group flex-nowrap">
							<div class="input-group-prepend">
								<span class="input-group-text" id="addon-wrapping">106512</span>
							</div>
							<input type="number" class="form-control" name="DepNum"
								id="InputDepNum" placeholder="两位数字"
								aria-describedby="addon-wrapping"
								oninput="value=value.slice(0,2)"
								value=<%=rs.getString("DepNum").substring(6, rs.getString("DepNum").length())%>
								required>
						</div>
						<%
						}
						%>
					</div>
					<div class="form-group col-md-6">
					<%
					if (DepNameFB == "不存在学院" || DepNameFB=="修改前后学院相同") {
					%>
					<label for="InputDepName">学院名称</label> 
					<input type="text"
						name="DepName" class="form-control" id="InputDepName"
						placeholder="如：金融学院/中国经济研究院" 
						value=<%=DepName %> required>
					<%
					}else if (DepNameFB == "存在学院") {
					%>
					<label for="InputDepName">学院名称</label> 
					<input type="text"
						name="DepName" class="form-control is-invalid" id="InputDepName"
						placeholder="如：金融学院/中国经济研究院" 
						value=<%=DepName %> required>
					<div class="invalid-feedback">该学院已有账号</div>
					<%}else if(DepNumFB==null){ %>
					<!-- 为空正常显示标签 -->
						<label for="InputDepName">学院名称</label> 
						<input type="text" name="DepName" class="form-control" 
						id="InputDepName" placeholder="如：金融学院/中国经济研究院"
						value=<%=rs.getString("DepName")%> required>
					<%} %>
					</div>
				</div>
				<div class="form-row">
					<div class="form-group col-md-6">
					<%
						if (submitFB == null) {
						%>
						<label for="InputDepConName">学院联系人姓名</label> <input type="text"
							placeholder="如：王雨华" name="DepConName" class="form-control"
							id="InputDepConName" value=<%=rs.getString("DepConName")%> required>
						<%
						} else if (submitFB == "提交失败") {
						%>
						<label for="InputDepConName">学院联系人姓名</label> <input type="text"
							placeholder="如：王雨华" name="DepConName" value=<%=DepConName%>
							class="form-control" id="InputDepConName" required>
						<%
						}
						%>
					</div>
					<div class="form-group col-md-4">
					<%
						if (submitFB == null) {
						%>
						<label for="InputDepConEmail1">邮箱账号</label> 
						<input type="text" placeholder="如：610197812" name="DepConEmail1"
						class="form-control" id="InputDepConEmail1" value=<%=UserDepConEmail1%> required>
						<%
						} else if (submitFB == "提交失败") {
						%>
						<label for="InputDepConEmail1">邮箱账号</label> <input type="text"
							placeholder="如：610197812" name="DepConEmail1"
							value=<%=DepConEmail1%> class="form-control"
							id="InputDepConEmail1" required>
						<%
						}
						%>
					</div>
					<div class="form-group col-md-2">
						<label for="InputDepConEmail2">域名</label> 
						<select name="DepConEmail2" id="InputDepConEmail2" class="form-control">
							<%
							if (UserDepConEmail2.equals("swufe.edu.cn")) {
							%>
							<option value="@swufe.edu.cn" selected>@swufe.edu.cn</option>
							<option value="@qq.com">@qq.com</option>
							<option value="@163.com">@163.com</option>
							<%
							} else if (UserDepConEmail2.equals("qq.com")) {
							%>
							<option value="@qq.com" selected>@qq.com</option>
							<option value="@swufe.edu.cn">@swufe.edu.cn</option>						
							<option value="@163.com">@163.com</option>
							<%
							} else if (UserDepConEmail2.equals("163.com")) {
							%>
							<option value="@163.com" selected>@163.com</option>
							<option value="@swufe.edu.cn">@swufe.edu.cn</option>
							<option value="@qq.com">@qq.com</option>
							<%
							} else if (DepConEmail2.equals("@swufe.edu.cn")) {
							%>
							<option value="@swufe.edu.cn" selected>@swufe.edu.cn</option>
							<option value="@qq.com">@qq.com</option>
							<option value="@163.com">@163.com</option>
							<%
							} else if (DepConEmail2.equals("@qq.com")) {
							%>
							<option value="@qq.com" selected>@qq.com</option>
							<option value="@swufe.edu.cn">@swufe.edu.cn</option>
							<option value="@163.com">@163.com</option>
							<%
							} else if (DepConEmail2.equals("@163.com")) {
							%>
							<option value="@163.com" selected>@163.com</option>
							<option value="@swufe.edu.cn">@swufe.edu.cn</option>
							<option value="@qq.com">@qq.com</option>
							<%
							}
							%>
						</select>
					</div>
				</div>
				<div class="form-row">
					<div class="form-group col-md-6">
						<button name="btn" type="submit" class="btn btn-primary" value="修改">修改</button>
						<button name="btn" type="submit" class="btn btn-primary" value="返回">返回</button>
					</div>

				</div>
			</form>
		</div>
<%}%>
<%
}catch(Exception e){
	// TODO Auto-generated catch block
	e.printStackTrace();
}%>

</body>
</html>